package cli.menu;

/**
 * BudgetBuoy
 * 
 * Simplify your personal expense management
 * 
 * @team cs2103jan13-w15-3j
 */

//--------------------------------------------------------------

/**
 * SearchSelectFilter Class
 * 
 * Description: 
 * 
 * 
 * @package   cli.menu
 * @author    Lai Yong Quan (A0080909Y)
 * @editor(s) -
 */

class SearchSelectFilter extends Function{

	private static final String[] SELECTION = {
		"-= Main menu > Search =-",
		"[b]: back [u]: undo [r]: redo [h]: home menu",
		"What would you like to filter your search results by?",
		"1. Name",
		"2. Date",
	};
	
	private static State BACK = State.MAINMENU;
	private static State CURRENT = State.SEARCHSELECTFILTER;
	
	public static State runMenu(){
		
	cli.print(SELECTION);
		

		String input = cli.nextLine();

		
		if(input.length() == 1){
			char charInput = input.charAt(0);
		if(tools.isHotKey(charInput))
			return hotKeyFunction(charInput);
		else return normFunction(charInput);
		}
		
		return CURRENT;
		
	}
	
	
	private static State normFunction(char charInput){
		
		State nextState = CURRENT;
		
	switch (charInput) {
	case '1':
		nextState = State.SEARCHBYNAME;
		break;
	case '2':
		nextState = State.SEARCHBYDATE;
		break;
	default:
		cli.print(INVALIDINPUT);
		break;
	}
	
	return nextState;
	}
	
	
	private static State hotKeyFunction(char charInput){
		State nextState = CURRENT;
		switch (charInput) {

		case 'u':
		case 'U':
			tools.undo();
			break;
		case 'r':
		case 'R':
			tools.redo();
			break;
		case 'h':
		case 'H':
			nextState = State.MAINMENU;
			break;
		case 'b':
		case 'B':
			nextState = BACK;
			break;
		default:
			break;
		}
		
		return nextState;
	}
	
}